package cn.edu.scau.cmi.tancuier.hibernate.dao;

import java.util.List;

import org.hibernate.LockOptions;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;

import cn.edu.scau.cmi.tancuier.hibernate.domain.Teacher;
import cn.edu.scau.cmi.tancuier.hibernate.factory.HibernateSessionFactory;

public class TeacherDAO {
	public static final String NAME = "name";
	private Session session = HibernateSessionFactory.getSession();
	
	public void save(Teacher tea) {
		try {
			Transaction transaction = session.beginTransaction();
			session.save(tea);
			transaction.commit();
		} catch (Exception e) {
			throw e;
		}
	}
	public void delete(Teacher tea) {
		try {
			Transaction transaction = session.beginTransaction();
			session.delete(tea);
			transaction.commit();
		}catch (Exception e) {
			throw e;
		}
	}
	public Teacher getById(long id) {
		try {
			Teacher inTeacher = (Teacher) session.get("cn.edu.scau.cmi.tancuier.hibernate.domain.Teacher", id);
			return inTeacher;
		} catch (Exception e) {
			throw e;
		}
	}
	
	public void attachDirty(Teacher instance) {
		try {
			Transaction transaction = session.beginTransaction();
			session.saveOrUpdate(instance);
			transaction.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void update(Teacher instance) {
		try {
			Transaction transaction = session.beginTransaction();
			session.update(instance);
			transaction.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}
}
